package com.example.demo;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("header")
@RestController
public class GetHeader {
    @RequestMapping("get")
    public String getHeader(HttpServletRequest request){
        String header = request.getHeader("User-Agent");
        return "从header中获取userAgent:"+ header;
    }

    @RequestMapping("get2")
    public String get2(@RequestHeader("Connection") String userAgent){
        return "从header中获取userAgent:"+ userAgent;
    }
}
